﻿using MediatR;
using RedDragon.Common.Domain.warehouse;
using RedDragon.Common.Infrastructure.Interface;
using T.Common.Domain.Common;

namespace RedDragon.RBAC.API.Application.Common.WarehouseW
{
    public class WarehouseCreateHandler : IRequestHandler<WarehouseCreateCommon,Result>
    {
        public IBaseRepository<Warehouse> WarehouseRepository;

        public WarehouseCreateHandler(IBaseRepository<Warehouse> warehouseRepository)
        {
            WarehouseRepository = warehouseRepository;
        }

        public  async Task<Result> Handle(WarehouseCreateCommon request, CancellationToken cancellationToken)
        {
            var result = new Result() {Code=0 ,Msg= "仓库新增失败" };
            try
            {
                var res = new Warehouse()
                {
                    WarehousNumBer = request.WarehousNumBer,
                    WarehouseName = request.WarehouseName,
                    WarehouseAddr = request.WarehouseAddr,
                    WarehouseRemark = request.WarehouseRemark,
                    WarehouseState = request.WarehouseState,
                    WarehouseCreateTime = DateTime.Now,
                    WarehouseCreateName = "",
                    WarehouseIsDel = false
                };
               var res1= await WarehouseRepository.Add(res);
                if (res1 != 0)
                { 
                      result.Code = 1;
                result.Msg = "仓库新增成功";
                }
              
               

            }
            catch (Exception)
            {

                throw;
            }
            return result;

        }
    }
}
